package com.xykj.mapper;

import com.xykj.common.entry.ChinaIndex;
import com.xykj.common.entry.NewStockCalendar;
import com.xykj.pojo.dto.NewStockCalendarDto;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

/**
 * @ClassDescription: 新股上市日历mapper层
 * @author:yzh
 * @create:2025/5/12 20:18
 **/
@Mapper
public interface NewStockCalendarMapper {
    /**
     * 查询本周（含本周周一~周日）上市的证券
     * @param startDate 本周周一
     * @param endDate   本周周日
     * @return DTO 列表
     */
    @Select("""
        SELECT 
          stock_name   AS stockName,
          listing_date AS listingDate
        FROM new_stock_calendar
        WHERE is_deleted = 0
          AND listing_date BETWEEN #{startDate} AND #{endDate}
        ORDER BY listing_date DESC
        LIMIT #{offset}, #{limit}
        """)
    List<NewStockCalendarDto> selectRecentWeek(
            @Param("startDate") LocalDate startDate,
            @Param("endDate") LocalDate endDate,
            @Param("offset")    int offset,
            @Param("limit")     int limit
    );

    @Select("select " +
            "count(1) " +
            " from new_stock_calendar ci where ci.is_deleted=0")
    Integer queryRecentWeekCount();

    /**
     * 爬虫存储数据
     * @param list
     */
    void batchInsert(List<NewStockCalendar> list);

    void batchDelete(@Param("ids") List<Long> ids);
    List<Long> selectExistingIds();
}
